package com.example.controller;

import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class UserController2 {
    // 注⼊⽅法2: 构造⽅法注入
    private final UserService userService; // 通常声明为final，确保依赖不可变

    @Autowired // 标注在构造方法上
    public UserController2(UserService userService) {
        this.userService = userService; // 通过构造方法参数注入
    }

    public void hello() {
        System.out.println("hi,UserController2...");
        userService.hello();
    }
}